package com.sunny.example.hwrealexame;

import java.util.*;
import java.util.stream.Collectors;

/**
 * 统计字母出现次数从大到小排序
 */
public class Exame3 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        while (scanner.hasNext()) {
            String input = scanner.nextLine();
            HashMap<Character, Integer> oc = new HashMap<>();
            for (int i = 0; i < input.length(); i++) {
                int index = i;
                int count = 1;
                char cha = input.charAt(i);

                while (index < input.length() - 1) {
                    if (cha == input.charAt(index + 1)) {
                        count++;
                    }
                    index++;
                }
                if (!oc.containsKey(cha))
                    oc.put(cha, count);
            }

            /**
             * 这里是个小技巧，将小写与大写分开，利用filter
             */
            List<Map.Entry<Character, Integer>> lowerCaseList = oc.entrySet().stream().filter(e -> e.getKey() >= 'a').collect(Collectors.toList());
            List<Map.Entry<Character, Integer>> upperCaseList = oc.entrySet().stream().filter(e -> e.getKey() <= 'Z').collect(Collectors.toList());

            sort(lowerCaseList);
            sort(upperCaseList);
            StringBuffer stringBuffer = new StringBuffer();
            stringBuffer.append(getResult(lowerCaseList));
            stringBuffer.append(getResult(upperCaseList));

            System.out.println(stringBuffer.toString());
        }
    }

    private static String getResult(List<Map.Entry<Character, Integer>> list) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Map.Entry<Character, Integer> entry : list) {
            stringBuffer.append(entry.getKey());
            stringBuffer.append(":");
            stringBuffer.append(entry.getValue());
            stringBuffer.append(";");
        }
        return stringBuffer.toString();
    }

    /**
     * 排序
     *
     * @param list
     */
    private static void sort(List<Map.Entry<Character, Integer>> list) {
        Collections.sort(list, new Comparator<Map.Entry<Character, Integer>>() {
            @Override
            public int compare(Map.Entry<Character, Integer> o1, Map.Entry<Character, Integer> o2) {
                if (o1.getValue() != o2.getValue()) {
                    return o2.getValue() - o1.getValue();
                }
                return o1.getKey() - o2.getKey();
            }
        });
    }
}
